--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<gpx version="1.0" creator="tsteven4" xmlns="http://www.topografix.com/GPX/1/0">
+ <wpt lat="48.8583701" lon="2.2922926">
+ <time>2018-07-06T05:04:03.750Z</time>
+ </wpt>
+ <wpt lat="48.8583701" lon="2.2922926">
+ <time>2018-07-06T05:04:03.250Z</time>
+ </wpt>
+ <wpt lat="48.8583701" lon="2.2922926">
+ <time>2018-07-07T05:04:03.750Z</time>
+ </wpt>
+ <wpt lat="48.8583701" lon="2.2922926">
+ <time>2018-07-05T05:04:03.750Z</time>
+ </wpt>
+</gpx>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<gpx version="1.0" creator="GPSBabel - http://www.gpsbabel.org" xmlns="http://www.topografix.com/GPX/1/0">
+ <time>1970-01-01T00:00:00Z</time>
+ <bounds minlat="48.858370100" minlon="2.292292600" maxlat="48.858370100" maxlon="2.292292600"/>
+ <wpt lat="48.858370100" lon="2.292292600">
+ <time>2018-07-05T05:04:03.750Z</time>
+ <name>WPT004</name>
+ <cmt>WPT004</cmt>
+ <desc>WPT004</desc>
+ </wpt>
+ <wpt lat="48.858370100" lon="2.292292600">
+ <time>2018-07-06T05:04:03.250Z</time>
+ <name>WPT002</name>
+ <cmt>WPT002</cmt>
+ <desc>WPT002</desc>
+ </wpt>
+ <wpt lat="48.858370100" lon="2.292292600">
+ <time>2018-07-06T05:04:03.750Z</time>
+ <name>WPT001</name>
+ <cmt>WPT001</cmt>
+ <desc>WPT001</desc>
+ </wpt>
+ <wpt lat="48.858370100" lon="2.292292600">
+ <time>2018-07-07T05:04:03.750Z</time>
+ <name>WPT003</name>
+ <cmt>WPT003</cmt>
+ <desc>WPT003</desc>
+ </wpt>
+</gpx>
#if FILTERS_ENABLED
+template <class T>
+inline int sgn(T v) {
+// Returns 1 if v > 0, -1 if v < 0, and 0 if v is zero
+ return (v > T(0)) - (v < T(0));
+}
+
int SortFilter::sort_comp(const queue* a, const queue* b)
{
const Waypoint* x1 = reinterpret_cast<const Waypoint *>(a);
case sm_description:
return x1->description.compare(x2->description);
case sm_time:
- return x1->GetCreationTime().toTime_t() - x2->GetCreationTime().toTime_t();
+ return sgn(x2->GetCreationTime().msecsTo(x1->GetCreationTime()));
default:
abort();
return 0; /* Internal caller error. */
--- /dev/null
+#
+# sort filter tests
+#
+
+rm -f ${TMPDIR}/sortfilter*
+
+gpsbabel -i gpx -f ${REFERENCE}/sortfilter_in.gpx -x sort,time -o gpx -F ${TMPDIR}/sortfilter_out.gpx
+compare ${REFERENCE}/sortfilter_out.gpx ${TMPDIR}/sortfilter_out.gpx
+